package evo.springboot.controller;

import evo.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ControllerTest {
    @RequestMapping(value = "/test")
    public ModelAndView test(){
        ModelAndView mv = new ModelAndView();
        User user = new User(1,"jojo",25);
        mv.addObject("user",user);
        mv.setViewName("view");
        return mv;
    }

    @RequestMapping(value = "/url")
    public ModelAndView url(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("id",444);
        mv.addObject("username","张三");
        mv.addObject("age",25);
        mv.setViewName("url");
        return mv;
    }

    @RequestMapping(value = "/test2")
    public @ResponseBody String test2(String username){
        return "请求参数是："+username;
    }

    @RequestMapping(value = "/test3")
    public @ResponseBody String test3(Integer id,String username,String age){
        return "id："+id+"\nusername: "+username+"\nage: "+age;
    }

    @RequestMapping(value = "/url2")
    public ModelAndView url2(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("id",444);
        mv.addObject("username","张三");
        mv.addObject("age",25);
        mv.setViewName("url2");
        return mv;
    }


    @RequestMapping(value = "/property")
    public String property(){
        return "property";
    }
}
